package com.wj.configclient.consul;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
//import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.core.env.Environment;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Properties;

@RestController
@EnableConfigurationProperties(TestConfig.class)
//@RefreshScope
public class ApplicationController {

    @Value("${value.test.1}")
    String value_test_1;
    @Value("${spring.redis.host}")
    String spring_redis_host;

    @Autowired
    private TestConfig testConfig;
    @Autowired
    Environment environment;
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @Value("${foo}")
    String foo;

    @RequestMapping(value = "/hi")
    public String hi() throws Exception {
        Properties properties = PropertiesLoaderUtils.loadAllProperties("application.properties");
        String listerCmd = properties.getProperty("value.test.1");

        try {
            System.out.println(redisTemplate.hasKey("xxxxx"));
        } catch (Exception e) {
            System.out.println(e.getLocalizedMessage());
        }
        System.out.println("value.test.1=" + value_test_1);
        System.out.println("PropertiesLoaderUtils:value.test.1=" + listerCmd);
        System.out.println("Environment:value.test.1=" + environment.getProperty("value.test.1"));
        System.out.println("test.properties.name=" + testConfig.getName());
        System.out.println("spring_redis_host=" + spring_redis_host);
        System.out.println("foo=" + foo);
        return "";
    }
}
